package com.cat.controller;

import com.cat.result.Result;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

@Controller
public class IndexController {
    private final static String PAGE_AUTH     = "frame/auth";
    @RequestMapping("/")
    public String index(){
        return "frame/index";
    }
    @RequestMapping("/main")
    public String main(){
        return "frame/main";
    }
    @RequestMapping("/login")
    public String login(){
        return "frame/login";
    }
//    @RequestMapping("/logout")
//    public String logout(HttpSession session){
//        /*session失效*/
//        session.invalidate();
//        return "redirect:/login";
//    }
    /**
     * 获取当前登录信息
     * @return
     */
    @GetMapping("getInfo")
    @ResponseBody
    public Object getInfo() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return authentication.getPrincipal();
    }
    @GetMapping("/auth")
    public String auth() {
        return PAGE_AUTH;
    }
}
